/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.hpi.generator.generator.distributors;

/**
 *
 * @author Michael
 */
public class BinomialDistributor  extends DataDistributor {
    private int aNumberOfTrials;
    private double aProbability;
    
    private double binomialCoefficient(int k, int n){
        double result = 0;
        if(k>n)
            result = 0;
        if(k==0 ||k ==n)
            result = 1;
        else{
            result = 1;
            for(int aIndex=1; aIndex <= k; aIndex++)
                result = result*(n-aIndex+1)/aIndex;
        }
        return result;
    }
    /**
     * @see http://de.wikipedia.org/wiki/Binomialverteilung
     * @param aValue
     * @return 
     */
    private int binomial(int aValue){
        int sum = 0;
        for(int aIndex = 0; aIndex < aValue; aIndex ++){
            sum+=binomialCoefficient(aNumberOfTrials, aIndex)*Math.pow(aProbability, aIndex) * Math.pow(1-aProbability, aNumberOfTrials - aIndex);
        }
        return sum*aNumberOfValuesToGenerate;
    }
    
    
    
    
}
